﻿layui.use(function () {
    var upload = layui.upload;
    var layer = layui.layer;
    var element = layui.element;
    var $ = layui.$;
    var laydate = layui.laydate;
    var form = layui.form;
    var table = layui.table;

    window.XiangBackfill = function XiangBackfill() {
        var QualityScheme = $("#Quaes").val()
        console.log(QualityScheme)
        // 先进行表格的初始渲染
        table.render({
            elem: '#carr',  // 表格元素的选择器
            page: {
                limit: 5,
                limits: [5, 8, 10]
            },
            cols: [[
                { type: 'checkbox', fixed: 'left' },
                { field: 'qualityinspectionName', title: '质检项目名称' },
                { field: 'qualityinspectionBH', title: '质检项目编号' },
                { field: 'qualityinspectionmethood', title: '质检方法' },
                { field: 'qualityinspectiontool', title: '质检工具' },
                { field: 'qualityinspectionmetype', title: '质检类型' },
                { field: 'standardvalue', title: '标准值' },
                { field: 'createdDate', title: '创建时间' },
                { field: 'createdBy', title: '创建人' },
                { field: 'remark', title: '备注' },

            ]],
            // 初始时可以先不加载数据，等待 ajax 请求成功后再更新
            data: []
        });

        $.ajax({
            url: '../Quality/QualitySpectionFanDo',
            type: 'get',
            data: {
                QualityPlanName: QualityScheme,
                token: ""
            },
            //contentType: 'application/json',
            success: function (res) {
                var res = JSON.parse(res)
                console.log(res)
                // 在 ajax 请求成功后，使用正确的表格 ID 进行 reload
                table.reload('carr', {
                    page: {
                        limit: 5,
                        limits: [5, 8, 10]
                    },
                    data: res.data
                });

            }
        })
    }
    //反填

    $(function () {
        fantian1();

    })
    //反填原料质检信息消息
    function fantian1() {
        // 发送AJAX请求获取数据
        console.log(localStorage.getItem("rawMaterialQualityId"))
        $.ajax({
            type: "get",
            url: "/Quality/RawGetid",
            data: {
                RawMaterialQualityId: localStorage.getItem("rawMaterialQualityId"),
                token: localStorage.getItem("token")
            },
            success: function (res) {
                var ter = JSON.parse(res)
                console.log(ter.data)

                $(ter.data).each(function () {
                    $('#QualityNumber').val(this.qualityNumber);
                    $('#QualityName').val(this.qualityName);
                    $('#QualityTime').val(this.qualityTime);
                    $('#Qualityer').val(this.qualityer);
                    $('#Supplier').val(this.supplier);
                    $('#MaterialNumber').val(this.materialNumber);
                    $('#MaterialName').val(this.materialName);
                    $('#Unit2').val(this.unit);
                    $('#SpecificationsModel').val(this.specificationsModel);
                    $('#batchNumber').val(this.batchNumber);
                    $('#Size').val(this.size);
                    $('#QualityType').val(this.qualityType);
                    $('#QualityScheme').val(this.qualityScheme);
                    $("[name='QualityS'][value='" + this.qualityS + "']").prop("checked", true);

                })

            },

        });


    }
    var obj = {

        "createdBy": "",
        "createdDate": "",
        "updatedBy": "",
        "updatedDate": "",
        "deletedBy": "",
        "deletedDate": "",
        "rawMaterialQualityId": "",
        "qualityNumber": "",
        "qualityName": "",
        "qualityTime": "",
        "qualityer": "",
        "supplier": "",
        "materialNumber": "",
        "materialName": "",
        "unit": "",
        "specificationsModel": "",
        "batchNumber": "",
        "size": "",
        "qualityType": "",
        "qualityScheme": "",
        "qualityS": "",
        "qualityNum": "",
        "acceptanceQuantity": "",
        "unqualifiedQuantity": "",
        "qualityInspector": "",
        "remark": "",
        "qualityResult": ""
    }
    window.DeviceUpdates = function DeviceUpdates() {
        obj.rawMaterialQualityId = localStorage.getItem("rawMaterialQualityId")
        obj.qualityNumber = $("#QualityNumber").val()
        obj.qualityName = $("#QualityName").val()
        obj.qualityTime = $("#QualityTime").val()
        obj.qualityer = $("#Qualityer").val()
        obj.supplier = $("#Supplier").val()
        obj.materialNumber = $("#MaterialNumber").val()
        obj.materialName = $("#MaterialName").val()
        obj.unit = $("#Unit").val()
        obj.specificationsModel = $("#SpecificationsModel").val()
        obj.batchNumber = $("#batchNumber").val()
        obj.size = $("#Size").val()
        obj.qualityType = $("#QualityType").val()
        obj.qualityScheme = $("#Quaes").val()
        obj.qualityS = $("[name='QualityS']:checked").val()
             obj.qualityNum= 0
            obj.acceptanceQuantity=0
            obj.unqualifiedQuantity=0
            obj.qualityInspector=""
            obj.remark=""
            obj.qualityResult=""
        // 取质检项目id
        var checkStatus = table.checkStatus('carr');
        var selectedIds = checkStatus.data.map(function (item) { return item.qualityinspectionId; });
        console.log(selectedIds)
        $.ajax({
            url: '../Quality/UpdateRawRaw',
            type: 'post',
            data: {
                obj1: obj,
                token: localStorage.getItem("token")
            },
            //contentType: 'application/json',
            success: function (res) {
                console.log(res)
                var res = JSON.parse(res)
                if (res.data > 0) {
                    alert("修改成功")
                    window.location.href = '/Quality/MaterialTable'
                }
                else {
                    alert("修改失败")
                }

            }
        })

    }


})









